package operation;

import abbot.finder.ComponentNotFoundException;
import abbot.finder.MultipleComponentsFoundException;
import abbot.finder.matchers.ClassMatcher;

import javax.swing.*;
import javax.swing.tree.TreeNode;
import java.util.ArrayList;

/**
 * Created by hanyz on 2017/10/27.
 */
public class ModelTreeOperation extends TreeOperation {
	ArrayList<TreeNode> treeNodes = new ArrayList<TreeNode>();
	JTree tree;

	public ModelTreeOperation() throws ComponentNotFoundException, MultipleComponentsFoundException {
		tree = (JTree) (new DockbarOperation("工具箱")).searchComponent(new ClassMatcher(JTree.class));
	}

	/**
	 * 选择树节点
	 * @param nodePath 列："数据导入","AutoCAD交换格式","导入.DXF"
	 * @return
	 */
	public ArrayList<TreeNode> selectTreeNode(String... nodePath){
		if(tree == null){
			System.out.println("工具箱树不存在。");
			return null;
		}
		if(nodePath == null || nodePath.length == 0){
			System.out.println("节点路径为空。");
			return null;
		}
		ArrayList<SearchMap> searchMapList = new ArrayList<>();
		for (String node : nodePath) {
			SearchMap searchMap = new SearchMap(SearchType.TEXT, node);
			searchMapList.add(searchMap);
		}
		treeNodes = TreeOperation.selectTreeNodes(tree,searchMapList);
		return treeNodes;
	}
}
